﻿#Region "Import"
Imports System.Windows.Forms
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports DevExpress.XtraEditors
#End Region

<DefaultEvent("Err"), Designer(GetType(BtnNuevoControlDesigner))> _
Public Class BtnNuevo
    <Category("Settings"), _
    DescriptionAttribute("Error event handler.")> Public Event Err(ByVal str As String)

    Private _Formulario As DevExpress.XtraEditors.XtraForm
    Public Property Formulario() As DevExpress.XtraEditors.XtraForm
        Get
            Return _Formulario
        End Get
        Set(ByVal Value As DevExpress.XtraEditors.XtraForm)
            _Formulario = Value
        End Set
    End Property

    Public Sub BtnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) handles me.Click
        LimpiarControles(_Formulario)
    End Sub

    Public Shared Sub LimpiarControles(ByVal Formulario As Control)
        For Each Objepto As Control In Formulario.Controls
            If Objepto.Controls.Count > 0 Then
                LimpiarControles(Objepto)
            End If
            Select Case UCase(TypeName(Objepto))
                Case "TEXTEDIT"
                    Select Case UCase(Objepto.Tag)
                        Case "ID"
                            CType(Objepto, TextEdit).EditValue = "0"
                            Exit Select
                        Case "DESCRIPCION FOCO"
                            CType(Objepto, TextEdit).EditValue = ""
                            CType(Objepto, TextEdit).Focus()
                            Exit Select
                        Case "TEXT"
                            CType(Objepto, TextEdit).EditValue = ""
                            Exit Select
                        Case "NUMERO"
                            CType(Objepto, TextEdit).EditValue = 0
                            Exit Select
                        Case "CODIGO FOCO"
                            CType(Objepto, TextEdit).EditValue = 0
                            CType(Objepto, TextEdit).Focus()
                            Exit Select
                    End Select
            End Select
        Next
    End Sub
End Class

#Region "SmartTag"

Public Class BtnNuevoControlDesigner
    Inherits System.Windows.Forms.Design.ControlDesigner

    Private lists As DesignerActionListCollection

    Public Overrides ReadOnly Property ActionLists() _
       As DesignerActionListCollection
        Get
            If lists Is Nothing Then
                lists = New DesignerActionListCollection()
                lists.Add(New BtnNuevoControlActionList(Me.Component))
            End If
            Return lists
        End Get
    End Property
End Class

Public Class BtnNuevoControlActionList
    Inherits System.ComponentModel.Design.DesignerActionList

    Private MiControl As BtnNuevo
    Private designerActionSvc As DesignerActionUIService = Nothing

    Public Sub New(ByVal component As IComponent)
        MyBase.New(component)
        Me.MiControl = component
        Me.designerActionSvc = CType(GetService(GetType(DesignerActionUIService)), DesignerActionUIService)
    End Sub

    Private Function GetPropertyByName(ByVal propName As String) As PropertyDescriptor
        Dim prop As PropertyDescriptor
        prop = TypeDescriptor.GetProperties(MiControl)(propName)

        If prop Is Nothing Then
            Throw New ArgumentException("Propiedad Invalida.", propName)
        Else
            Return prop
        End If
    End Function

    Public Property Formulario() As DevExpress.XtraEditors.XtraForm
        Get
            Return MiControl.Formulario
        End Get
        Set(ByVal value As DevExpress.XtraEditors.XtraForm)
            GetPropertyByName("Formulario").SetValue(MiControl, value)
        End Set
    End Property

    Public Property Text() As String
        Get
            Return MiControl.Text
        End Get
        Set(ByVal value As String)
            GetPropertyByName("Text").SetValue(MiControl, value)
        End Set
    End Property

End Class

#End Region
